@@ -11,11 +11,13 @@ from pywe_storage import RedisStorage |
||
| 11 | 11 |
from TimeConvert import TimeConvert as tc |
| 12 | 12 |
|
| 13 | 13 |
from account.models import UserInfo |
| 14 |
-from mch.models import BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, LatestAppInfo, ModelInfo, OperatorInfo |
|
| 14 |
+from mch.models import (AdministratorInfo, BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, LatestAppInfo, |
|
| 15 |
+ ModelInfo, OperatorInfo) |
|
| 15 | 16 |
from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo, |
| 16 | 17 |
ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo) |
| 17 |
-from utils.error.errno_utils import (OperatorStatusCode, ProductBrandStatusCode, ProductDistributorStatusCode, |
|
| 18 |
- ProductModelStatusCode, SaleclerkStatusCode, UserStatusCode) |
|
| 18 |
+from utils.error.errno_utils import (AdministratorStatusCode, OperatorStatusCode, ProductBrandStatusCode, |
|
| 19 |
+ ProductDistributorStatusCode, ProductModelStatusCode, SaleclerkStatusCode, |
|
| 20 |
+ UserStatusCode) |
|
| 19 | 21 |
from utils.redis.connect import r |
| 20 | 22 |
|
| 21 | 23 |
|
@@ -44,6 +46,27 @@ def login_api(request): |
||
| 44 | 46 |
|
| 45 | 47 |
|
| 46 | 48 |
@logit |
| 49 |
+def admin_login_api(request): |
|
| 50 |
+ phone = request.POST.get('phone', '')
|
|
| 51 |
+ password = request.POST.get('password', '')
|
|
| 52 |
+ |
|
| 53 |
+ try: |
|
| 54 |
+ administrator = AdministratorInfo.objects.get(phone=phone, status=True) |
|
| 55 |
+ except AdministratorInfo.DoesNotExist: |
|
| 56 |
+ return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND) |
|
| 57 |
+ |
|
| 58 |
+ if administrator.user_status == OperatorInfo.DISABLED: |
|
| 59 |
+ return response(AdministratorStatusCode.ADMINISTRATOR_NOT_ACTIVATED) |
|
| 60 |
+ |
|
| 61 |
+ if not check_password(password, administrator.encryption): |
|
| 62 |
+ return response(AdministratorStatusCode.ADMINISTRATOR_PASSWORD_ERROR) |
|
| 63 |
+ |
|
| 64 |
+ request.session['admin_id'] = administrator.admin_id |
|
| 65 |
+ |
|
| 66 |
+ return response(200, 'Admin Login Success', u'管理员登录成功') |
|
| 67 |
+ |
|
| 68 |
+ |
|
| 69 |
+@logit |
|
| 47 | 70 |
def bmd_infos(request): |
| 48 | 71 |
optor_id = request.POST.get('optor_id', '')
|
| 49 | 72 |
|
@@ -0,0 +1,140 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+ |
|
| 3 |
+from __future__ import division |
|
| 4 |
+ |
|
| 5 |
+from django.conf import settings |
|
| 6 |
+from django.contrib.auth.hashers import check_password, make_password |
|
| 7 |
+from django_logit import logit |
|
| 8 |
+from django_response import response |
|
| 9 |
+from paginator import pagination |
|
| 10 |
+from pywe_miniapp import get_phone_number |
|
| 11 |
+from pywe_storage import RedisStorage |
|
| 12 |
+from TimeConvert import TimeConvert as tc |
|
| 13 |
+ |
|
| 14 |
+from account.models import UserInfo |
|
| 15 |
+from mch.models import (AdministratorInfo, BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, LatestAppInfo, |
|
| 16 |
+ ModelInfo, OperatorInfo) |
|
| 17 |
+from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo, |
|
| 18 |
+ ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo) |
|
| 19 |
+from utils.error.errno_utils import (AdministratorStatusCode, OperatorStatusCode, ProductBrandStatusCode, |
|
| 20 |
+ ProductDistributorStatusCode, ProductModelStatusCode, SaleclerkStatusCode, |
|
| 21 |
+ UserStatusCode) |
|
| 22 |
+from utils.redis.connect import r |
|
| 23 |
+ |
|
| 24 |
+ |
|
| 25 |
+WECHAT = settings.WECHAT |
|
| 26 |
+ |
|
| 27 |
+ |
|
| 28 |
+@logit |
|
| 29 |
+def operator_add(request): |
|
| 30 |
+ name = request.POST.get('name', '')
|
|
| 31 |
+ phone = request.POST.get('phone', '')
|
|
| 32 |
+ password = request.POST.get('password', '')
|
|
| 33 |
+ |
|
| 34 |
+ admin_id = request.session.get('admin_id')
|
|
| 35 |
+ |
|
| 36 |
+ try: |
|
| 37 |
+ administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True) |
|
| 38 |
+ except AdministratorInfo.DoesNotExist: |
|
| 39 |
+ return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND) |
|
| 40 |
+ |
|
| 41 |
+ try: |
|
| 42 |
+ operator = OperatorInfo.objects.get(brand_id=administrator.brand_id, phone=phone, user_status=OperatorInfo.ACTIVATED, status=True) |
|
| 43 |
+ except OperatorInfo.DoesNotExist: |
|
| 44 |
+ operator = None |
|
| 45 |
+ |
|
| 46 |
+ if operator: |
|
| 47 |
+ return response(OperatorStatusCode.OPERATOR_PHONE_ALREADY_EXISTS) |
|
| 48 |
+ |
|
| 49 |
+ encryption = make_password(password, settings.MAKE_PASSWORD_SALT, settings.MAKE_PASSWORD_HASHER) |
|
| 50 |
+ |
|
| 51 |
+ OperatorInfo.objects.create( |
|
| 52 |
+ brand_id=administrator.brand_id, |
|
| 53 |
+ name=name, |
|
| 54 |
+ phone=phone, |
|
| 55 |
+ encryption=encryption, |
|
| 56 |
+ ) |
|
| 57 |
+ |
|
| 58 |
+ return response(200, 'Operator Add Success', u'操作员添加成功') |
|
| 59 |
+ |
|
| 60 |
+ |
|
| 61 |
+@logit |
|
| 62 |
+def operator_delete(request): |
|
| 63 |
+ operator_id = request.POST.get('operator_id', '')
|
|
| 64 |
+ |
|
| 65 |
+ admin_id = request.session.get('admin_id')
|
|
| 66 |
+ |
|
| 67 |
+ try: |
|
| 68 |
+ administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True) |
|
| 69 |
+ except AdministratorInfo.DoesNotExist: |
|
| 70 |
+ return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND) |
|
| 71 |
+ |
|
| 72 |
+ try: |
|
| 73 |
+ operator = OperatorInfo.objects.get(brand_id=administrator.brand_id, operator_id=operator_id, status=True) |
|
| 74 |
+ except OperatorInfo.DoesNotExist: |
|
| 75 |
+ return response(OperatorStatusCode.OPERATOR_NOT_FOUND) |
|
| 76 |
+ |
|
| 77 |
+ if operator.user_status == OperatorStatusCode.OPERATOR_HAS_DISABLED: |
|
| 78 |
+ return response(OperatorStatusCode.OPERATOR_HAS_DISABLED) |
|
| 79 |
+ elif operator.user_status == OperatorStatusCode.OPERATOR_HAS_DELETED: |
|
| 80 |
+ return response(OperatorStatusCode.OPERATOR_HAS_DELETED) |
|
| 81 |
+ |
|
| 82 |
+ operator.user_status = OperatorInfo.DELETED |
|
| 83 |
+ operator.save() |
|
| 84 |
+ |
|
| 85 |
+ return response(200, 'Operator Delete Success', u'操作员删除成功') |
|
| 86 |
+ |
|
| 87 |
+ |
|
| 88 |
+@logit |
|
| 89 |
+def operator_update(request): |
|
| 90 |
+ operator_id = request.POST.get('operator_id', '')
|
|
| 91 |
+ name = request.POST.get('name', '')
|
|
| 92 |
+ password = request.POST.get('password', '')
|
|
| 93 |
+ |
|
| 94 |
+ admin_id = request.session.get('admin_id')
|
|
| 95 |
+ |
|
| 96 |
+ try: |
|
| 97 |
+ administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True) |
|
| 98 |
+ except AdministratorInfo.DoesNotExist: |
|
| 99 |
+ return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND) |
|
| 100 |
+ |
|
| 101 |
+ try: |
|
| 102 |
+ operator = OperatorInfo.objects.get(brand_id=administrator.brand_id, operator_id=operator_id, status=True) |
|
| 103 |
+ except OperatorInfo.DoesNotExist: |
|
| 104 |
+ return response(OperatorStatusCode.OPERATOR_NOT_FOUND) |
|
| 105 |
+ |
|
| 106 |
+ if operator.user_status == OperatorStatusCode.OPERATOR_HAS_DISABLED: |
|
| 107 |
+ return response(OperatorStatusCode.OPERATOR_HAS_DISABLED) |
|
| 108 |
+ elif operator.user_status == OperatorStatusCode.OPERATOR_HAS_DELETED: |
|
| 109 |
+ return response(OperatorStatusCode.OPERATOR_HAS_DELETED) |
|
| 110 |
+ |
|
| 111 |
+ if name: |
|
| 112 |
+ operator.name = name |
|
| 113 |
+ if password: |
|
| 114 |
+ operator.encryption = make_password(password, settings.MAKE_PASSWORD_SALT, settings.MAKE_PASSWORD_HASHER) |
|
| 115 |
+ |
|
| 116 |
+ operator.save() |
|
| 117 |
+ |
|
| 118 |
+ return response(200, 'Operator Update Success', u'操作员更新成功') |
|
| 119 |
+ |
|
| 120 |
+ |
|
| 121 |
+@logit |
|
| 122 |
+def operator_list(request): |
|
| 123 |
+ page = request.POST.get('page', 1)
|
|
| 124 |
+ num = request.POST.get('num', 20)
|
|
| 125 |
+ |
|
| 126 |
+ admin_id = request.session.get('admin_id')
|
|
| 127 |
+ |
|
| 128 |
+ try: |
|
| 129 |
+ administrator = AdministratorInfo.objects.get(admin_id=admin_id, user_status=AdministratorInfo.ACTIVATED, status=True) |
|
| 130 |
+ except AdministratorInfo.DoesNotExist: |
|
| 131 |
+ return response(AdministratorStatusCode.ADMINISTRATOR_NOT_FOUND) |
|
| 132 |
+ |
|
| 133 |
+ optors = OperatorInfo.objects.filter(brand_id=administrator.brand_id, user_status=OperatorInfo.ACTIVATED, status=True) |
|
| 134 |
+ optors, left = pagination(optors, page, num) |
|
| 135 |
+ optors = [optor.data for optor in optors] |
|
| 136 |
+ |
|
| 137 |
+ return response(200, 'Get Operator List Success', u'获取操作员列表成功', {
|
|
| 138 |
+ 'optors': optors, |
|
| 139 |
+ 'left': left, |
|
| 140 |
+ }) |
@@ -5,7 +5,7 @@ from django_file_upload import views as file_views |
||
| 5 | 5 |
|
| 6 | 6 |
from account import tourguide_views |
| 7 | 7 |
from account import views as account_views |
| 8 |
-from api import encrypt_views, mch_views |
|
| 8 |
+from api import encrypt_views, mch_views, operator_views |
|
| 9 | 9 |
from box import views as box_views |
| 10 | 10 |
from geo import views as geo_views |
| 11 | 11 |
from group import (groupuser_views, lensman_views, tourguidegroup_views, tourguidegroupadmin_views, |
@@ -189,6 +189,7 @@ urlpatterns += [ |
||
| 189 | 189 |
# Kodo |
| 190 | 190 |
urlpatterns += [ |
| 191 | 191 |
url(r'^login$', mch_views.login_api, name='login_api'), |
| 192 |
+ url(r'^admin/login$', mch_views.admin_login_api, name='admin_login_api'), |
|
| 192 | 193 |
] |
| 193 | 194 |
|
| 194 | 195 |
urlpatterns += [ |
@@ -232,3 +233,10 @@ urlpatterns += [ |
||
| 232 | 233 |
url(r'^tj/consumer$', tj_views.tj_consumer, name='tj_consumer'), # 统计数据(消费者维度) |
| 233 | 234 |
url(r'^tj/generate$', tj_views.tj_generate, name='tj_generate'), # 统计数据生成 |
| 234 | 235 |
] |
| 236 |
+ |
|
| 237 |
+urlpatterns += [ |
|
| 238 |
+ url(r'^operator/add$', operator_views.operator_add, name='operator_add'), |
|
| 239 |
+ url(r'^operator/delete$', operator_views.operator_delete, name='operator_delete'), |
|
| 240 |
+ url(r'^operator/update$', operator_views.operator_update, name='operator_update'), |
|
| 241 |
+ url(r'^operator/list$', operator_views.operator_list, name='operator_list'), |
|
| 242 |
+] |
@@ -0,0 +1,25 @@ |
||
| 1 |
+# -*- coding: utf-8 -*- |
|
| 2 |
+# Generated by Django 1.11.11 on 2018-05-14 07:19 |
|
| 3 |
+from __future__ import unicode_literals |
|
| 4 |
+ |
|
| 5 |
+from django.db import migrations, models |
|
| 6 |
+ |
|
| 7 |
+ |
|
| 8 |
+class Migration(migrations.Migration): |
|
| 9 |
+ |
|
| 10 |
+ dependencies = [ |
|
| 11 |
+ ('mch', '0017_auto_20180508_1830'),
|
|
| 12 |
+ ] |
|
| 13 |
+ |
|
| 14 |
+ operations = [ |
|
| 15 |
+ migrations.AlterField( |
|
| 16 |
+ model_name='administratorinfo', |
|
| 17 |
+ name='user_status', |
|
| 18 |
+ field=models.IntegerField(choices=[(1, '\u5df2\u6fc0\u6d3b'), (2, '\u5df2\u7981\u7528'), (3, '\u5df2\u5220\u9664')], db_index=True, default=1, help_text='\u7ba1\u7406\u5458\u72b6\u6001', verbose_name='user_status'), |
|
| 19 |
+ ), |
|
| 20 |
+ migrations.AlterField( |
|
| 21 |
+ model_name='operatorinfo', |
|
| 22 |
+ name='user_status', |
|
| 23 |
+ field=models.IntegerField(choices=[(1, '\u5df2\u6fc0\u6d3b'), (2, '\u5df2\u7981\u7528'), (3, '\u5df2\u5220\u9664')], db_index=True, default=1, help_text='\u64cd\u4f5c\u5458\u72b6\u6001', verbose_name='user_status'), |
|
| 24 |
+ ), |
|
| 25 |
+ ] |
@@ -9,10 +9,12 @@ from shortuuidfield import ShortUUIDField |
||
| 9 | 9 |
class AdministratorInfo(BaseModelMixin): |
| 10 | 10 |
ACTIVATED = 1 |
| 11 | 11 |
DISABLED = 2 |
| 12 |
+ DELETED = 3 |
|
| 12 | 13 |
|
| 13 | 14 |
USER_STATUS_TUPLE = ( |
| 14 | 15 |
(ACTIVATED, u'已激活'), |
| 15 | 16 |
(DISABLED, u'已禁用'), |
| 17 |
+ (DELETED, u'已删除'), |
|
| 16 | 18 |
) |
| 17 | 19 |
|
| 18 | 20 |
admin_id = ShortUUIDField(_(u'admin_id'), max_length=32, blank=True, null=True, help_text=u'管理员唯一标识', db_index=True, unique=True) |
@@ -39,10 +41,12 @@ class AdministratorInfo(BaseModelMixin): |
||
| 39 | 41 |
class OperatorInfo(BaseModelMixin): |
| 40 | 42 |
ACTIVATED = 1 |
| 41 | 43 |
DISABLED = 2 |
| 44 |
+ DELETED = 3 |
|
| 42 | 45 |
|
| 43 | 46 |
USER_STATUS_TUPLE = ( |
| 44 | 47 |
(ACTIVATED, u'已激活'), |
| 45 | 48 |
(DISABLED, u'已禁用'), |
| 49 |
+ (DELETED, u'已删除'), |
|
| 46 | 50 |
) |
| 47 | 51 |
|
| 48 | 52 |
operator_id = ShortUUIDField(_(u'operator_id'), max_length=32, blank=True, null=True, help_text=u'操作员唯一标识', db_index=True, unique=True) |
@@ -65,6 +69,14 @@ class OperatorInfo(BaseModelMixin): |
||
| 65 | 69 |
def __unicode__(self): |
| 66 | 70 |
return u'{}-{}'.format(self.name, self.phone)
|
| 67 | 71 |
|
| 72 |
+ @property |
|
| 73 |
+ def data(self): |
|
| 74 |
+ return {
|
|
| 75 |
+ 'operator_id': self.operator_id, |
|
| 76 |
+ 'phone': self.phone, |
|
| 77 |
+ 'name': self.name, |
|
| 78 |
+ } |
|
| 79 |
+ |
|
| 68 | 80 |
|
| 69 | 81 |
class BrandInfo(BaseModelMixin): |
| 70 | 82 |
brand_id = ShortUUIDField(_(u'brand_id'), max_length=32, help_text=u'品牌唯一标识', db_index=True, unique=True) |
@@ -69,13 +69,30 @@ class TourGuideStatusCode(BaseStatusCode): |
||
| 69 | 69 |
TOURGUIDE_NOT_ACTIVATED = StatusCodeField(400115, 'Tour Guide Not Activated', description=u'导游帐号未激活') |
| 70 | 70 |
|
| 71 | 71 |
|
| 72 |
-class OperatorStatusCode(BaseStatusCode): |
|
| 72 |
+class AdministratorStatusCode(BaseStatusCode): |
|
| 73 | 73 |
""" 操作员相关错误码 4002xx """ |
| 74 |
- OPERATOR_NOT_FOUND = StatusCodeField(400201, 'Operator Not Found', description=u'操作员不存在') |
|
| 74 |
+ ADMINISTRATOR_NOT_FOUND = StatusCodeField(400201, 'Administrator Not Found', description=u'管理员不存在') |
|
| 75 |
+ # 密码 |
|
| 76 |
+ ADMINISTRATOR_PASSWORD_ERROR = StatusCodeField(400202, 'Administrator Password Error', description=u'管理员密码错误') |
|
| 77 |
+ # 手机号 |
|
| 78 |
+ ADMINISTRATOR_PHONE_ALREADY_EXISTS = StatusCodeField(400205, 'Administrator Phone Already Exists', description=u'管理员手机号已经存在') |
|
| 79 |
+ # 状态 |
|
| 80 |
+ ADMINISTRATOR_NOT_ACTIVATED = StatusCodeField(400215, 'Administrator Not Activated', description=u'管理员未激活') |
|
| 81 |
+ ADMINISTRATOR_HAS_DISABLED = StatusCodeField(400216, 'Administrator Has Disabled', description=u'管理员已禁用') |
|
| 82 |
+ ADMINISTRATOR_HAS_DELETED = StatusCodeField(400217, 'Administrator Has Deleted', description=u'管理员已删除') |
|
| 83 |
+ |
|
| 84 |
+ |
|
| 85 |
+class OperatorStatusCode(BaseStatusCode): |
|
| 86 |
+ """ 操作员相关错误码 4003xx """ |
|
| 87 |
+ OPERATOR_NOT_FOUND = StatusCodeField(400301, 'Operator Not Found', description=u'操作员不存在') |
|
| 75 | 88 |
# 密码 |
| 76 |
- OPERATOR_PASSWORD_ERROR = StatusCodeField(400202, 'Operator Password Error', description=u'操作员密码错误') |
|
| 89 |
+ OPERATOR_PASSWORD_ERROR = StatusCodeField(400302, 'Operator Password Error', description=u'操作员密码错误') |
|
| 90 |
+ # 手机号 |
|
| 91 |
+ OPERATOR_PHONE_ALREADY_EXISTS = StatusCodeField(400305, 'Operator Phone Already Exists', description=u'操作员手机号已经存在') |
|
| 77 | 92 |
# 状态 |
| 78 |
- OPERATOR_NOT_ACTIVATED = StatusCodeField(400215, 'Operator Not Activated', description=u'操作员未激活') |
|
| 93 |
+ OPERATOR_NOT_ACTIVATED = StatusCodeField(400315, 'Operator Not Activated', description=u'操作员未激活') |
|
| 94 |
+ OPERATOR_HAS_DISABLED = StatusCodeField(400316, 'Operator Has Disabled', description=u'操作员已禁用') |
|
| 95 |
+ OPERATOR_HAS_DELETED = StatusCodeField(400317, 'Operator Has Deleted', description=u'操作员已删除') |
|
| 79 | 96 |
|
| 80 | 97 |
|
| 81 | 98 |
class UserStatusCode(BaseStatusCode): |